package demo2;
import java.lang.Object;
public class TestDemo2 {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<>();
        myArray.setValue(1,293);
        myArray.setValue(2,23);
        System.out.println(myArray.getValue(1));
        System.out.println(myArray.getValue(2));
        System.out.println("----------");
        MyArray<String> myArray1 = new MyArray<>();
        myArray1.setValue(1,"wdadw");
        myArray1.setValue(2,"dawaddw");
        System.out.println(myArray1.getValue(1));
        System.out.println(myArray1.getValue(2));
    }
}

class MyArray<T> {
    public Object[] arr = new Object[10];//注意 它不能 new
//    public T[] arr2 = new T[10];//error
    public T getValue(int pos) {
        return (T)arr[pos];
    }
    public void setValue(int pos, T val) {
        arr[pos] = val;
    }
}
